<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
 <div id="app">
       总价格{{totalPrice}}
     </div>


     <script src="js/vue.js"></script>
     <script>
       const app=new Vue({
         el: '#app',
         data: {
           message:'你好vue',
           books:[
             {name:'java',price:100},
             {name:'python',price:200},
             {name:'vue',price:300},
             {name:'javascript',price:400},
           ]
         },
         computed:{
           totalPrice:function(){
              // let total=0;
              // for(let book of this.books){
              //   total+=book.price;
              // }
              // return total;
              return this.books.reduce((preValue,element)=>preValue+element.price,0)
           }
         }
       })
     </script>
</body>
</html>